<?php

namespace App\Http\Controllers;

//获取充值任务列表
use App\Common\Sql;

class RechargeTaskList extends Base
{
    public function logic()
    {
        if (!isset($this->param['uid'])) {
            return $this->returnError(1, "please input uid");
        }
        $uid      = $this->param['uid'];
        $data     = array();
        $cur_time = time();
        $row      =  Sql::select('t_recharge_task_conf',[['status',1]]);

        //拿用户充值了多少钱
//        $recharge_num         = $this->get_user_recharge_num($uid, strtotime("2018-01-10"), strtotime("2018-02-01"));
        $recharge_num         = 1;
        $data['recharge_num'] = $recharge_num;
        foreach ($row as $info) {
            $task_info  = array();
            $begin_time = strtotime($info['begin_time']);
            $end_time   = strtotime($info['end_time']);
            //检查是否在活动时间内
            if ($cur_time < $begin_time || $cur_time > $end_time) {
                continue;
            }
            $taskid                  = (int)$info['id'];
            $task_info['task_id']    = $taskid;
            $task_info['task_name']  = $info['name'];
            $price                   = (int)$info['price'];
            $task_info['price']      = $price;
            $task_info['begin_time'] = $info['begin_time'];
            $task_info['end_time']   = $info['end_time'];
            //从redis里获取用户任务完成状态
            $is_finish = $this->get_user_recharge_task_status($uid, $taskid);
            if ($is_finish) {
                $task_info['is_finish'] = 1;//已经领取
            } else {
                if ($recharge_num >= $price) {
                    $task_info['is_finish'] = 2;//等待领取
                } else {
                    $task_info['is_finish'] = 3;//没资格领取
                }
            }
            $reward = $info['reward'];
            //解析任务奖品
            $rewards = explode('|', $reward);
            foreach ($rewards as $items) {
                $item_num = explode('=', $items);
                if (count($item_num) != 2) {
                    continue;
                }
                $item['itemid']             = (int)$item_num[0];
                $item['num']                = (int)$item_num[1];
                $task_info['reward_list'][] = $item;
            }
            $data['task_list'][] = $task_info;
        }
        $lottery_item          = 25008;
        $data['lottery_count'] = $this->get_user_item_num($uid, $lottery_item);
        $data['uid']           = $uid;
        $data['item_rand']     = 16;
        $data['lottery_item']  = $lottery_item;
        $data['item_rotate'][] = array('id' => 40006, 'rotate' => 324);
        $data['item_rotate'][] = array('id' => 40025, 'rotate' => 72);
        $data['item_rotate'][] = array('id' => 10007, 'rotate' => 144);
        $data['item_rotate'][] = array('id' => 10009, 'rotate' => 36);
        $data['item_rotate'][] = array('id' => 40013, 'rotate' => 288);
        $data['item_rotate'][] = array('id' => 40015, 'rotate' => 216);
        return $this->returnData($data);
    }

}
